package com.cxcy.swustlearner.mapper;

import com.cxcy.swustlearner.pojo.Task;
import com.cxcy.swustlearner.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TaskMapper {
    @Insert("insert into task (title,content,src,class_id,major_id,college_id,start_time,end_time,permission,publisher_id,task_id) values (#{title},#{content},#{src},#{classId},#{majorId},#{collegeId},NOW(),NOW(),#{permission},#{publisherId},#{taskId})")
    void insertTask(String title, String content, String src, String classId,String majorId,String collegeId,int permission,String publisherId,String taskId);
    @Select("select * from task")
    List<Task> selectTask();
    @Select("select * from task where class_id=#{classId} and major_id=#{majorId} and college_id=#{collegeId} and permission=1")//查看班级发布的任务
    List<Task> selectTaskByClassId(String classId,String majorId,String collegeId);
    @Select("select * from task where college_id=#{collegeId} and permission=3")
    List<Task> selectTaskByCollegeId(String collegeId);
    @Select("select * from task where major_id=#{majorId} and college_id=#{collegeId} and permission=2")//查看专业发布的任务
    List<Task> selectTaskByMajorId(String majorId,String collegeId);
    @Select("select * from task where publisher_id=#{publisherId}")//无论权限高低，查看自己发布的任务
    List<Task> selectTaskByPublisherId(String publisherId);
    @Select("select * from task where publisher_id=#{publisherId} and permission=0")//权限高的人查看自己发布的任务
    List<Task> selectTaskByPublisherIdAndPermission(String publisherId);
    @Delete("delete from task where task_id=#{taskId}")//id即为taskId
    void deleteTaskByTaskId(Integer taskId);
    void updateTask(Task task);
    @Select("select * from task where task_id=#{taskId}")
    Task selectTaskByTaskId(String taskId);
}